package com.czy.util.json;

import com.czy.convert.Converter;
import com.czy.util.time.TimeFormat;
import com.czy.util.time.TimeUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;

public class SerializerLocalDateTime2Str extends JsonSerializer<LocalDateTime> implements Converter<LocalDateTime,String> {
    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeString(convert(value));
    }

    @Override
    public String convert(LocalDateTime source) {
        return TimeUtil.time2Str(source, TimeFormat.yyyy_MM_dd_HH_mm_ss_SSS);
    }
}
